#coding:utf-8
#じゃんけん 2022/11/2 N.SUN
import os
import random
winCnt = loseCnt = 0
#関数定義
def pchand():
pc = random.randint(0,2)
return pc
def player():
h = '5'
while h not in ['1','2','3']:
h = input(' \t\t >>>>> 1: チョキ 2: パー 3: ぐー <<<<<\n')
if h not in ['1','2','3']:
print ("入力ミス。もう一度選んでください。")
hand = int(h) - 1
return hand
def janken(x):
global winCnt,loseCnt
hname = ["チョキ","パー","ぐー"]
for i in range(1,x+1):
pc = pchand()
hand = player()
print(i,'回目: pcは' + hname[pc] + "を、あなたは" + hname[hand] + "を出しました。", end=' ')
if hand == pc:
print(' あいこ! (~^~)\n')
elif hand == (pc + 1) % 3:
print(' パソコンの勝ち! (T_T) \n')
loseCnt += 1
else:
print('あなたの勝ち!!! \(^O^)/ \n')
winCnt += 1
def showAnswer(x):
global winCnt,loseCnt
rate = winCnt / x
drawCnt = x - winCnt - loseCnt
ans ="\n あなたは{}回じゃんけんをした. {}回が勝ち, {}回負け, {}回あいこでした. 勝率は{:.2f}.\n"
print(ans.format(x,winCnt,loseCnt,drawCnt, rate))
#関数呼出し
os.system('clear')
y = int(input("何回じゃんけんをしたい? "))
print('------------------------じゃんけん-------------------------')
janken(y)
showAnswer(y)